class Animal {
    public String name;
    public int age;
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Animal(String name, int age)");
    }

    public void eat() {
        System.out.println(this.name+"正在吃.....");
    }
}

class Dog extends Animal {
    public String color;

    public Dog(String name,int age,String color) {
        //调用父类的 带有2个参数的构造方法 来初始化父类当中成员 必须在第一行 所以，super()和this() 是不能同时存在的
        super(name,age);
        this.color = color;
        //System.out.println("Dog(String name,int age,String color)");
    }
    public void barks() {
        System.out.println(this.name+" 正在叫.....");
    }

    public void eat() {
        System.out.println(this.name+" 正在吃狗粮......");
    }
}
class Bird extends Animal {

    public Bird(String name,int age) {
        super(name,age);
    }

    public void fly() {
        System.out.println(this.name +" 正在飞....");
    }

    public void eat() {
        System.out.println(this.name+" 正在吃鸟粮....");
    }
}

public class Test {
    public static void fun(Animal animal){
        animal.eat();
    }
    public static Animal fun2() {
        return new Bird("布谷",1);
    }
    //什么是向上转型 -》 发生多态的条件之一
    public static void main(String[] args) {
        Dog dog = new Dog("旺财",2,"红色");
        //Animal animal = dog;
        //父类引用 引用了子类对象
        //Animal animal = new Dog("旺财",2,"红色");
        fun(dog);
        //animal.eat();
        Bird bird = new Bird("百灵",1);
       //fun(bird);
        Animal animal2 = bird;
        animal2.eat();
       // animal.barks();//通过Animal这个引用 只能调用Animal自己的属性
        Bird bird1 = (Bird)animal2;
        bird.fly();
        Animal animal1 = new Dog("旺财",3,"红色");
        //
        if(animal1 instanceof Bird) {
            Bird bird2 = (Bird) animal1;
            bird2.fly();
        }else {
            System.out.println("hello");
        }
    }

    public static void main1(String[] args) {
        Dog dog = new Dog("旺财",2,"红色");
        dog.eat();
        dog.barks();

        Animal animal = new Animal("动物",3);
        animal.eat();
        //animal.barks();//通过Animal这个引用 只能调用Animal自己的属性

    }
}